package com.ruoyi.system.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.system.domain.DisplayTest;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.DisplayTestVo;
import com.ruoyi.system.domain.bo.DisplayTestBo;
import com.ruoyi.system.service.IDisplayTestService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 显示器检测
 *
 * @author Panda
 * @date 2023-11-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/test")
public class DisplayTestController extends BaseController {

    private final IDisplayTestService iDisplayTestService;

    /**
     * 获取显示器信息
     * @return
     */
    @GetMapping("displays")
    public R getDisplays(@Validated(QueryGroup.class) DisplayTestBo bo) {
        String poId = bo.getPoId();
        String remark = bo.getRemark();
       return iDisplayTestService.getDisplays(poId , remark);
    }

    /**
     * 查询显示器检测列表
     */
    @SaCheckPermission("system:displayerTest:list")
    @GetMapping("/list")
    public TableDataInfo<DisplayTestVo> list(DisplayTestBo bo, PageQuery pageQuery) {
        return iDisplayTestService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出显示器检测列表
     */
    @SaCheckPermission("system:displayerTest:export")
    @Log(title = "显示器检测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DisplayTestBo bo, HttpServletResponse response) {
        List<DisplayTestVo> list = iDisplayTestService.queryList(bo);
        ExcelUtil.exportExcel(list, "显示器检测", DisplayTestVo.class, response);
    }

    /**
     * 获取显示器检测详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:displayerTest:query")
    @GetMapping("/{id}")
    public R<DisplayTestVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iDisplayTestService.queryById(id));
    }

    /**
     * 新增显示器检测
     */
    @SaCheckPermission("system:displayerTest:add")
    @Log(title = "显示器检测", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DisplayTestBo bo) {
        return toAjax(iDisplayTestService.insertByBo(bo));
    }

    /**
     * 修改显示器检测
     */
    @SaCheckPermission("system:displayerTest:edit")
    @Log(title = "显示器检测", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DisplayTestBo bo) {
        return toAjax(iDisplayTestService.updateByBo(bo));
    }

    /**
     * 删除显示器检测
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:displayerTest:remove")
    @Log(title = "显示器检测", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iDisplayTestService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
